package main;

import main.common.LogicThread;
import main.common.ThreadLock;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class App {
    public static ServerSocket serverSocket;
    static Scanner input = new Scanner(System.in);
    public static void main(String[] args) {
        initSocket();
        System.out.println("Server start success");
//        while (true){
//            System.out.println("==============");
//            System.out.println("Menu");
//            System.out.println("1");
//            System.out.println("2");
//            System.out.println("3");
//            System.out.println("==============");
//            String command = input.nextLine();
//            if (command.equals("sessions")) {
//
//            } else if (command.equals("use")) {
//                while (true) {
//                    try {
//                        Thread.sleep(500);
//                        System.out.println("command");
//                        synchronized (ThreadLock.lockobj) {
//                            ThreadLock.command = input.nextLine();
//                            ThreadLock.lockobj.notify();
//                            ThreadLock.lockobj.wait();
//                        }
//                    } catch (Exception e){
//
//                    }
//                }
//            } else {
//
//            }
//        }
    }

    public static void initSocket(){
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Socket socket = null;
                    serverSocket = new ServerSocket(9999);
                    int i = 0;
                    while (true){
                        i++;
                        socket = serverSocket.accept();
                        new LogicThread(socket);
                    }
                }catch (Exception e){
                    System.out.printf("init socket error: %s", e);
                }
            }
        });
        thread.start();
    }

}
